package com.zzyl.serve.controller;

import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.serve.domain.NursingPlan;
import com.zzyl.serve.domain.NursingPlanDto;
import com.zzyl.serve.service.INursingPlanService;
import com.zzyl.serve.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 护理计划Controller
 * 
 * @author Jiagege
 * @date 2025-07-19
 */
@RestController
@RequestMapping("/nursing/plan")
@Slf4j
@Api("护理计划")
public class NursingPlanController extends BaseController
{
    @Autowired
    private INursingPlanService nursingPlanService;

    /**
     * 查询护理计划列表
     */
    @PreAuthorize("@ss.hasPermi('serve:plan:list')")
    @GetMapping("/list")
    public TableDataInfo list(NursingPlan nursingPlan)
    {
        startPage();
        List<NursingPlan> list = nursingPlanService.selectNursingPlanList(nursingPlan);
        return getDataTable(list);
    }

    /**
     * 导出护理计划列表
     */
    @PreAuthorize("@ss.hasPermi('serve:plan:export')")
    @Log(title = "护理计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NursingPlan nursingPlan)
    {
        List<NursingPlan> list = nursingPlanService.selectNursingPlanList(nursingPlan);
        ExcelUtil<NursingPlan> util = new ExcelUtil<NursingPlan>(NursingPlan.class);
        util.exportExcel(response, list, "护理计划数据");
    }

    /**
     * 获取护理计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('serve:plan:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取护理计划详细信息", notes = "根据id获取护理计划详细信息")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        NursingPlanVo nursingPlanVo = nursingPlanService.selectNursingPlanById(id);
        return success(nursingPlanVo);
    }

    /**
     * 新增护理计划
     */
    @PreAuthorize("@ss.hasPermi('serve:plan:add')")
    @Log(title = "护理计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NursingPlanDto nursingPlanDto)
    {

        nursingPlanService.insertNursingPlan(nursingPlanDto);
        log.info("护理计划添加成功");
        return success("护理计划添加成功");
    }

    /**
     * 修改护理计划
     */
    @ApiOperation(value = "修改护理计划", notes = "修改指定id的护理计划信息")
    @PreAuthorize("@ss.hasPermi('serve:plan:edit')")
    @Log(title = "护理计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NursingPlanDto dto)
    {
        System.out.println("dto.getId() = " + dto.getId());
        nursingPlanService.updateNursingPlan(dto);
        log.info("护理计划修改成功");
        return success();
    }

    /**
     * 删除护理计划
     */
    @PreAuthorize("@ss.hasPermi('serve:plan:remove')")
    @Log(title = "护理计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Integer id)
    {

        return toAjax(nursingPlanService.deleteNursingPlanByIds(id));
    }

    @GetMapping("/all")
    @ApiOperation("查询护理计划")
    public AjaxResult getAllNursingPlans() {
        List<NursingPlan> nursingPlans = nursingPlanService.listAll();
        return AjaxResult.success(nursingPlans);
    }

}